Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gramio/keyboards

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gramio/keyboards

Framework-agnostic Telegram bot keyboard builder with many cool features!

  • 0.3.3
  • npm
  • Socket score

Version published
Weekly downloads
289
decreased by-14.24%
Maintainers
1
Weekly downloads
 
Created
Source

@gramio/keyboards

Framework-agnostic Telegram bot keyboard (and inline query result) builder with many cool features!

npm JSR JSR Score

Installation (if you don't use GramIO)

npm i @gramio/keyboards

See more in Documentation

Usage (with frameworks)

Simple Keyboard

import { Keyboard } from "@gramio/keyboards";

const keyboard = new Keyboard()
    .text("first row")
    .row()
    .text("second row")
    .build(); // NOTE: In GramIO, you don't have to use the ".build" method

Usage with Frameworks

Send via GramIO

import { Bot, Keyboard } from "gramio"; // import from GramIO package!!

const bot = new Bot(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.send("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla"),
    });
});

Send via Grammy

import { Keyboard } from "@gramio/keyboards";
import { Bot } from "grammy";

const bot = new Bot(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.reply("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla")
            .build(),
    });
});

bot.start();

Send via Telegraf

[!WARNING] The Telegraf does not support the latest version of Bot API

import { Keyboard } from "@gramio/keyboards";
import { Telegraf } from "telegraf";

const bot = new Telegraf(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.reply("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla")
            .build(),
    });
});

bot.launch();

Send via puregram

import { Telegram } from "puregram";
import { Keyboard } from "@gramio/keyboards";

const bot = new Telegram({
    token: process.env.TOKEN as string,
});

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.send("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla")
            .build(),
    });
});

bot.updates.startPolling();

Send via node-telegram-bot-api

[!WARNING] The node-telegram-bot-api does not support the latest version of Bot API and the types are badly written, so the types may not match

import { Keyboard } from "@gramio/keyboards";
import TelegramBot from "node-telegram-bot-api";

const bot = new TelegramBot(process.env.TOKEN as string, { polling: true });

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (msg) => {
    return bot.sendMessage(msg.chat.id, "test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla")
            .build(),
    });
});
Result
{
    "keyboard": [
        [
            {
                "text": "simple keyboard"
            }
        ],
        [
            {
                "text": "Apple"
            }
        ],
        [
            {
                "text": "Realme"
            }
        ],
        [
            {
                "text": "Xiaomi"
            }
        ]
    ],
    "one_time_keyboard": false,
    "is_persistent": false,
    "selective": false,
    "resize_keyboard": true
}

image

Keywords

FAQs

Package last updated on 28 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc